home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
PROGRAMR
/
GSRC208A.ZIP
/
GEPOUT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-18
|
16KB
|
596 lines
#include "copyleft.h"
/*
GEPASI - a simulator of metabolic pathways and other dynamical systems
Copyright (C) 1989, 1992 Pedro Mendes
*/
/*************************************/
/* */
/* output module */
/* */
/* (dynamic data is output by */
/* the dynamic() function) */
/* */
/* Zortech C/C++ 3.0 r4 */
/* MICROSOFT C 6.00 */
/* Visual C/C++ 1.0 */
/* QuickC/WIN 1.0 */
/* ULTRIX cc */
/* GNU gcc */
/* */
/* (include here compilers that */
/* compiled GEPASI successfully) */
/* */
/*************************************/
#include <stdio.h>
/*#include <conio.h>*/
#include <string.h>
#include <math.h>
#include <time.h>
#include "globals.h"
#include "globvar.h"
#include "datab.h"
#include "newton.h"
#include "metconan.h"
#include "lsoda.h"
#include "pmu.h"
#include "heapchk.h"
void report_header( FILE *ch );
void out_rstoi( FILE *o );
void out_rinv( FILE *o );
/* print an error message */
void out_error( int n )
{
printf( "\n%s\n", errormsg[n] );
}
int dat_fileovr( void )
{
FILE *ch1;
/*unlink*/
ch1 = fopen( options.datname, "wt" ); /* open output for .dat */
if ( ch1 == NULL ) /* fopen failed ? */
{
if( options.debug )
printf("\n * dat_out() - fatal error: couldn't open file %s\n", options.datname );
return -1;
}
fclose( ch1 );
return 0;
}
int dat_nl( void )
{
FILE *ch1;
ch1 = fopen( options.datname, "at" ); /* open output for .dat */
if ( ch1 == NULL ) /* fopen failed ? */
{
if( options.debug )
printf("\n * dat_out() - fatal error: couldn't open file %s\n", options.datname );
return -1;
}
fprintf(ch1,"\n");
fclose( ch1 );
return 0;
}
int dat_titles( void )
{
FILE *ch1;
char *ptr;
char delim;
int i;
switch( options.datsep )
{
case 0: delim = ' '; break;
case 1: delim = ','; break;
case 2: delim = '\t'; break;
default: delim = ' ';
}
ch1 = fopen( options.datname, "at" ); /* open output for .dat */
if ( ch1 == NULL ) /* fopen failed ? */
{
if( options.debug )
printf("\n * dat_out() - fatal error: couldn't open file %s\n", options.datname );
return -1;
}
ptr = outtit;
for(i=0;i<totsel;i++)
{
if( i ) fprintf(ch1,"%c", delim );
if( options.quotes ) fprintf(ch1,"\"" );
fprintf(ch1,"%.*s%*s", options.datwidth, ptr, options.datwidth-strlen(ptr), "" );
if( options.quotes ) fprintf(ch1,"\"" );
do{ }while( *ptr++ );
}
fprintf(ch1,"\n");
fclose( ch1 );
return 0;
}
int dat_values( void )
{
FILE *ch1;
int i;
char delim;
switch( options.datsep )
{
case 0: delim = ' '; break;
case 1: delim = ','; break;
case 2: delim = '\t'; break;
default: delim = ' ';
}
ch1 = fopen( options.datname, "at" ); /* open output for .dat */
if ( ch1 == NULL ) /* fopen failed ? */
{
if( options.debug )
printf("\n * dat_out() - fatal error: couldn't open file %s\n", options.datname );
return -1;
}
for(i=0;i<totsel;i++)
{ /* output values */
if( i ) fprintf(ch1,"%c", delim );
fprintf(ch1,"% -*.*le", options.datwidth, options.datwidth-8, *(poutelem[i]));
}
fprintf(ch1,"\n");
fclose( ch1 );
return 0;
}
int dat_error( void )
{
FILE *ch1;
/* char delim;
switch( options.datsep )
{
case 0: delim = ' '; break;
case 1: delim = ','; break;
case 2: delim = '\t'; break;
default: delim = ' ';
}*/
ch1 = fopen( options.datname, "at" ); /* open output for .dat */
if ( ch1 == NULL ) /* fopen failed ? */
{
if( options.debug )
printf("\n * dat_error() - fatal error: couldn't open file %s\n", options.datname );
return -1;
}
/* for(i=0;i<totsel;i++)
{ */ /* output values */
/* if( i ) fprintf(ch1,"%c", delim );*/
/*fprintf(ch1,"% -*.*le", options.datwidth, options.datwidth-8, (double) 0 );*/
/* for(j=0;j<options.datwidth;j++) fprintf(ch1," ");
}*/
fprintf(ch1,"\n");
fclose( ch1 );
return 0;
}
void report_init( int p )
{
FILE *ch1;
char mode[4];
int i,j,k;
char *ptr, auxstr[10];
if( options.append ) strcpy( mode, "at" );
else strcpy( mode, "wt" );
strcpy( repfile, filename[p] );
fixext( repfile, '.', ".txt" );
ch1 = fopen( repfile, mode );
if( options.append ) fprintf( ch1, "\n" ); /* separate from previous */
report_header( ch1 );
fprintf( ch1, "\n%s\n", topname ); /* pathway title */
/* output struct filen */
if ( options.structan )
{
fprintf(ch1,"\nREDUCED STOICHEIOMETRY MATRIX\n");
out_rstoi( ch1 );
fprintf(ch1,"\nINVERSE OF THE REDUCTION MATRIX\n");
out_rinv( ch1 );
}
/* info about moieties */
if ( depmet > 0 )
{
fprintf(ch1,"\nCONSERVATION RELATIONSHIPS\n");
for( i=indmet; i<nmetab; i++ )
{
for(j=0, k=0;j<totmet;j++)
if ( intmet[j] )
if (ld[i][j] != (float) 0)
{
sprintf(auxstr, "%s ", k ? "+" : " " );
if (ld[i][j] > (float) 1)
sprintf(auxstr, "%s %3.1f*", k ? "+" : " ", ld[i][j] );
else if (ld[i][j] < (float) -1)
sprintf(auxstr, "- %3.1f*", fabs(ld[i][j]));
else if (ld[i][j] == (float) -1)
sprintf(auxstr, "- ");
fprintf(ch1,"%s[%s] ", auxstr, metname[j] );
k++;
}
fprintf(ch1,"= %.4lg %s\n", moiety[i], options.concu);
}
}
else
fprintf(ch1,"\nNO CONSERVATION RELATIONSHIPS\n");
fprintf(ch1,"\nKINETIC PARAMETERS\n"); /* output kinetic p. */
for( i=0; i<nsteps; i++ )
{
fprintf(ch1,"%s (%s)\n",stepname[i], ktype[kinetype[i]].descr);
ptr = ktype[kinetype[i]].constnam;
for(j=0;j<(int)ktype[kinetype[i]].nconst; j++)
{
fprintf(ch1," %s = % .4le\n", ptr, params[i][j] );
do{ } while( *(ptr++) );
}
}
fclose(ch1);
}
void report_dyn( void )
{
FILE *ch1;
int i;
ch1 = fopen( repfile, "at" );
/* output concentrations */
fprintf( ch1, "\nRESULTS OF INTEGRATION (after %.2le %s)\n", endtime, options.timeu );
for( i=0; i<totmet; i++ )
fprintf(ch1,"[%s] initial = % .6le %s, final = % .6le %s%s\n",
metname[i], x0[i], options.concu, x[i],
options.concu, x[i] >= 0 ? "" : " BOGUS!");
/* output fluxes */
for( i=0; i<nsteps; i++ )
fprintf( ch1, "J(%s) = % .6le %s/%s\n", stepname[i], flux[i], options.concu, options.timeu );
fclose(ch1);
}
void report_ss( int diverge, int ccfs )
{
FILE *ch1;
int i,j,k;
double moi;
char auxstr[10];
ch1 = fopen( repfile, "at" );
if( diverge == N_OK )
{
/* check if steady state is an equilibrium */
if ( equilibrium() )
fprintf(ch1,"\nEQUILIBRIUM SOLUTION\n");
else
fprintf(ch1,"\nSTEADY STATE SOLUTION\n");
/* concentrations */
for( i=0; i<totmet; i++ )
{
fprintf(ch1,"[%s] = % .6le %s, tt = % .6le %s, rate = % .3le %s/%s",
metname[i], xss[i], options.concu, tt[i], options.timeu,
rate[i], options.concu, options.timeu);
if( xss[i] < 0 ) fprintf(ch1," BOGUS!");
fprintf(ch1,"\n");
}
/* mass conservation */
if ( depmet > 0 )
{
for( i=indmet; i<nmetab; i++ )
{
moi = 0;
for(j=0, k=0;j<totmet;j++)
if ( intmet[j] )
if (ld[i][j] != (float) 0)
{
moi += (double)ld[i][j] * xss[j];
sprintf(auxstr, "%s ", k ? "+" : " " );
if (ld[i][j] > (float) 1)
sprintf(auxstr, "%s